from sqlalchemy import Column, Integer, String, Boolean, Enum
from sqlalchemy.orm import relationship
from app.db.database import Base
import enum

class UserType(enum.Enum):
    USER = "user"
    ADMIN = "admin"

class User(Base):
    __tablename__ = "users"
    
    id = Column(Integer, primary_key=True, index=True)
    openid = Column(String(100), unique=True, index=True, nullable=True)
    username = Column(String(50), unique=True, index=True)
    password = Column(String(100), nullable=True)
    nickname = Column(String(50))
    avatar = Column(String(200), nullable=True)
    user_type = Column(Enum(UserType), default=UserType.USER)
    permission_level = Column(Integer, default=0)
    is_active = Column(Boolean, default=True)
    
    # 关系
    activities = relationship("Activity", back_populates="publisher")
    announcements = relationship("Announcement", back_populates="publisher")
    form_submissions = relationship("FormSubmission", back_populates="user") 